package cn.rslee.java.demos;

public class JavaDemo {

	//1.Hello world
	public static void main(String[] args) {
		System.out.println("Hello World!");
	}
	
	//2.定义变量
	String name = "rslee";
	int age = 28;
	
	//3.定义常量
	
	final long distance = 1000000;
	
	//4.私有变量
	private double width = 182.03;
	
	//5.判断语句
	
	void showIf(String name){
		if(name == null){
			System.out.println("the name is null");
		}else{
			System.out.println("the name:"+name);
		}
	}
	
	//6.while 循环
	
	void showWhile(){
		int x = 1;
		while(x < 5){
			System.out.println(x);
			x += 1;
		}
		
		do{
			System.out.println(x);
			x -= 1;
		}while(x < 1);
	}
	
	//7.for 循环
	
	void showFor(){
		
		for(int i=0 ; i <= 100 ; i++){
			System.out.println(i);
		}
		
		for(int i=1 ; i < 100 ; i++){
			System.out.println(i);
		}
		
		// 打印偶数
		for(int i=1 ; i <= 100 ; i++){
			if(i % 2 ==0){
				System.out.println(i);
			}
		}
		//同时循环
		for(int x=1,y=100 ; x <= 100 & y >=1 ; x++,y--){
			System.out.println(String.format("%d/%d=%.1f",x,y,x*y));
		}
		
		//break
		for(int x =1; x<= 100 ; x++){
			if(x >= 60) break;
		}
	}
	
	// 8.方法定义
	int f(int x){
		return x * x;
	}
	
	//多参数定义
	int a(int x,int y){
		return x + y;
	}
	// 无参
	void d(){
		System.out.println("None");
	}
	
	// 9.类定义
	
	class C{
		
		private int age;
		private String name;
		
		public C(int age,String name){
			this.age =age;
			this.name = name;
		}
		
		public void say(){
			System.out.println("My name is "+name+", age "+age);
		}
		
	}
	
	//类继承
	class F{
		void say(){
			System.out.println("I'm F");
		}
	}
	
	class FA extends F{
		//重写
		void say(){
			System.out.println("I'm FA");
		}
		//重载
		void say(String name){
			System.out.println("I'm "+name);
		}
	}

}

//10.单例模式

class S{
	final static int age = 28;
	private static S s = null;
	
	private S(){
		
	}
	
	public static S getInstance(){
		if(s == null){
			s = new S();
		}
		return s;
	}
	
	static void say(){
		System.out.println("age "+age);
	}
	
}
